#include "credit.h"
#include "ui_credit.h"

credit::credit(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::credit)
{
    ui->setupUi(this);
    book_sql bok;
    bok_db=bok.book_db;
}

credit::~credit()
{
    delete ui;
}

void credit::on_info_search_clicked()
{
    qDebug()<<"on_info_search_clicked";
    QString s=QString(ui->ID->text());
    QSqlQuery sql(bok_db);
    QString bksql = QString("SELECT * FROM Reader WHERE ID=%1").arg(s);
    sql.exec(bksql);
    if(sql.next())//先将原本框里内容清空再插入数值
    {
        qDebug()<<"Found";
        ui->book_borrowed->clear();
        ui->book_borrowed->insert(sql.value(11).toString());
        ui->book_overtime->clear();
        ui->book_overtime->insert(sql.value(10).toString());
    }

}

void credit::on_credit_return_clicked()
{
    QString s=QString(ui->ID->text());
                QSqlQuery sql(bok_db);
                QString bksql = QString("SELECT * FROM Reader WHERE ID=%1").arg(s);
                sql.exec(bksql);
                if(sql.next())//先将原本框里内容清空再插入数值
                {
                    qDebug()<<"Found";
                    ui->book_borrowed->clear();
                    ui->book_borrowed->insert(sql.value(11).toString());
                    ui->book_overtime->clear();
                    ui->book_overtime->insert(sql.value(10).toString());
                }
            if(ui->book_overtime->text().toInt()==0)
            {
                QMessageBox::information(this,tr("提示对话框"),tr("信用良好，不需要答题！"), QMessageBox::Ok);
                         return;
            }
            QA.show();
            QA.refresh();
            QA.ID = QString(ui->ID->text());
}

